﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIT.Controls;
using System.Xml;

namespace UIT.Web.Renderers
{
	class BorderRenderer : WebControlRenderer<Border>
	{
		public override void Render(Border control)
		{
			writer.WriteStartElement("div");
			control.RenderKeyBindings();
			control.BeginRenderFullStyle(writer);
			control.Style.Render(writer);
			if (control.BorderBrush != null)
			{
				StringBuilder sb;
				if (control.BorderThickness.IsUniform)
				{
					sb = new StringBuilder("; border:");
					control.RenderBorder(sb, control.BorderThickness.Left);
				}
				else
				{
					sb = new StringBuilder("border-left:");
					control.RenderBorder(sb, control.BorderThickness.Left);
					sb.Append("; border-top:");
					control.RenderBorder(sb, control.BorderThickness.Top);
					sb.Append("; border-right:");
					control.RenderBorder(sb, control.BorderThickness.Right);
					sb.Append("; border-bottom:");
					control.RenderBorder(sb, control.BorderThickness.Bottom);
				}
				writer.WriteRaw(sb.ToString());
			}
			control.EndRenderStyle(writer);

			if (!string.IsNullOrEmpty(control.Id))
				writer.WriteAttributeString("id", control.Id);
			if (control.TabIndex.HasValue)
				writer.WriteAttributeString("tabIndex", control.TabIndex.Value.ToString());
			Manager.Render(control.Child);
			writer.WriteEndElement();
		}
	}
}
